package com.xthink.web.controller;

import com.xthink.common.result.AjaxResult;
import com.xthink.common.vo.user.*;
import com.xthink.web.service.CardsService;
import com.xthink.web.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private CardsService cardsService;

    //注册
    @PostMapping("/register")
    public AjaxResult register(@RequestBody UserRegisterVo userVo){

     return userService.register(userVo);
    }

    //登录
    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginVo userLoginDto){
        return userService.login(userLoginDto);
    }

    //账号退出
    @PostMapping("/logout")
    private AjaxResult logout(){
        return userService.logout();
    }

    //密码找回
    @PostMapping("/retrieve")
    public AjaxResult retrieve(@RequestBody UserRetrieveVo userRetrieveVo){
        return userService.retrieve(userRetrieveVo);
    }

    //用户添加
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody UserInsertVo userInsertVo){
        return userService.insert(userInsertVo);
    }

    //管理员添加
    @PostMapping("/adminInsert")
    public AjaxResult adminInsert(@RequestBody AdminInsertVo adminInsertVo){
        return userService.adminInsert(adminInsertVo);
    }

    //管理员编辑
    @PostMapping("/adminUpdate")
    public AjaxResult adminUpdate(@RequestBody AdminUpdateVo adminUpdateVo){
        return userService.adminUpdate(adminUpdateVo);
    }

    //管理员删除
    @GetMapping("/deleteAdmin/{id}")
    public AjaxResult deleteAdmin(@PathVariable("id") Integer id){
        return userService.deleteAdmin(id);
    }

    //管理员分页及模糊查询
    @PostMapping("likeListAdmin")
    public AjaxResult likeListAdmin(@RequestBody LikeListAdminVo likeListAdminVo){
        return userService.likeListAdmin(likeListAdminVo);
    }

    //模糊查询
    @PostMapping("/list")
    public AjaxResult likeList(@RequestBody UserListVo userListVo){
        return userService.likeList(userListVo);
    }

    //分页查询
    @PostMapping("/page")
    private AjaxResult pageInfo(@RequestBody UserPageVo userPageVo){
        return userService.pageInfo(userPageVo);
    }

    //逻辑删除删除
    @GetMapping("/delete/{id}")
    private AjaxResult deleteById(@PathVariable("id") Integer id){
        return userService.deleteById(id);
    }

    //修改信息
    @PostMapping("/update")
    private AjaxResult updateOne(@RequestBody UserUpdateVo userUpdateVo){
        return userService.updateOne(userUpdateVo);
    }

    //审核
    @PostMapping("/audi")
    private AjaxResult audi(@RequestBody UserAudiVo userAudiVo){
        return userService.audi(userAudiVo);
    }

    //经销商下拉框
    @GetMapping("/selectBusiness")
    public AjaxResult selectBusiness(){
        return userService.selectBusiness();
    }

    //经销商内部卡片
    @PostMapping("/userListCards")
    public AjaxResult userListCards(@RequestBody UserListCardsVo userListCardsVo){
        return cardsService.userListCards(userListCardsVo);
    }

    //批量调拨
    @GetMapping("/binDingUser/{ids}/{businessName}")
    public AjaxResult binDingUser(@PathVariable("ids")Integer[] ids,@PathVariable("businessName")String businessName){
        return cardsService.binDingUser(ids,businessName);
    }

    //批量解绑
    @GetMapping("/unBinDingUser/{ids}")
    public AjaxResult unBinDingUser(@PathVariable("ids")Integer[] ids){
        return cardsService.unBinDingUser(ids);
    }
}
